﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Text;
using System.Threading;

using FRL.DebtChased.Repository;
using FRL.DebtChased.ServiceUtilities;

namespace FRL.DebtChased.ClockworkService
{

	/// <summary>
	/// Declaration of MessagingWorker class
	/// </summary>
	class MessagingWorker : BaseWorker
	{

		// Note: Background worker class to assign new accounts and process
		// existing accounts.

		/////////////////////////////////////////////////////////////
		// Implementation

		protected override string ThreadName
		{
			get { return "Messaging"; }
		}

		protected override bool _doWork()
		{

			// Declare return variable
			bool bWorkDone = false;

			// Process the comms-out queue
			bWorkDone = _processCommsOutQueue();

			// Process the comms-in queue
			if(!bWorkDone)
				bWorkDone = _processCommsInQueue();

			// Return variable
			return bWorkDone;

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private bool _processCommsOutQueue()
		{

			// Declare return variable
			bool bFtmp = false;

			// TODO
			// Load the next unprocessed record in the comms-out queue
			// and send comms-out item
			// Print letters
			// Fax faxes
			// Send SMS messages
			// Send emails

			// Return variable
			return bFtmp;

		}

		private bool _processCommsInQueue()
		{

			// Declare return variable
			bool bFtmp = false;

			// TODO
			// Read POP3 email queue for incoming email
			// and assign to accounts, or mark as unknown account

			// Return variable
			return bFtmp;

		}

	}

}
